package cn.winwintech.Incense.web.controller;

import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.base.webapp.respm.BaseResp;
import com.base.webapp.respm.ResException;
import com.base.webapp.respm.WeatherInfo;

import cn.winwintech.Incense.client.request.WeatherReq;
import cn.winwintech.Incense.service.WeatherService;

@Controller
public class WeatherController {
	@Autowired
	private WeatherService service;

	@RequestMapping(value = "/weather/forecast")
	public @ResponseBody BaseResp getForecast(@Valid WeatherReq req, BindingResult result) {
		BaseResp resp = new BaseResp();
		if (resp.processResultValid(result)) {
			try {
				//
				String areaId = req.getAreaId();
				if (areaId == null) {
					areaId = "101310101";
				}
				String json = service.getForecast(areaId);
				String json2 = service.fetchInfo(areaId);
				resp.setData(new WeatherInfo(json,json2));
			} catch (Exception e) {
				resp.bindException((ResException) e);
			}
		}
		return resp;

	}
}
